# -*- coding: utf-8 -*-
"""
Created on Tue Aug 14 20:43:43 2018

@author: Hy
"""

from bs4 import BeautifulSoup

import requests


def get_html_text(url):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36'
    }
    try:
        r = requests.get(url, timeout=30, headers=headers)
        r.raise_for_status()
        r.encoding = r.apparent_encoding
        return r.content
    except Exception as e:
        print(e)
        return None

url = 'http://dx.sc.chinaz.com/Files/DownLoad/sound1/201604/7158.mp3'
data = get_html_text(url)
with open('喘息.mp3', 'wb') as f:
    f.write(data)